package com.smbms.controller;

import com.smbms.pojo.User;
import com.smbms.service.UserService;
import com.smbms.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;

@Controller
public class LoginController {
    @Autowired
    UserService userService;

    @ResponseBody
    @RequestMapping(value = "/userLogin",method = RequestMethod.POST)
    public Result Login(@RequestBody User user, HttpSession session) {
        User loginUser = userService.login(user);
        if(loginUser != null){
            //登录成功，存储用户信息到Session会话中
            session.setAttribute("LOGIN_USER", loginUser);
            return new Result(true, "登陆成功", loginUser);
        }else{
            return new Result(false, "账号或密码输入错误");
        }
    }
}
